package com.atjava.nebula.core.exception.support;

import java.util.HashMap;
import java.util.Map;

import com.atjava.nebula.core.exception.bean.ExceptionInfo;
import com.atjava.nebula.core.exception.config.ParseExpInfoXML;
/**
 * 创建一个单例模式的ExceptionInfo缓存
 */
public class ExceptionInfoCache {

	private static ExceptionInfoCache SINGLETON = new ExceptionInfoCache();

	private Map<String, ExceptionInfo> ecache = new HashMap<String, ExceptionInfo>();

	private ExceptionInfoCache() {
		try {
			ecache = ParseExpInfoXML.parseXML("/expinfo.xml");			
		} catch (Throwable t) {
			ecache = null;
		}
	}	

	public static ExceptionInfoCache getInstance() {
		if(SINGLETON == null) {
			return new ExceptionInfoCache() ;
		}
		return SINGLETON;
	}

	public ExceptionInfo getExceptionInfo(String errorId) {
		if (ecache == null)
			return null;
		return (ExceptionInfo) ecache.get(errorId);
	}
}